import request from './request';

/**
 * 获取区域代理仪表盘数据
 * @returns {Promise}
 */
export function getAgentDashboard() {
  return request({
    url: '/agent/dashboard',
    method: 'get',
  });
}

/**
 * 获取区域代理经销商列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getAgentDistributors(params) {
  return request({
    url: '/agent/distributors',
    method: 'get',
    params,
  });
}

/**
 * 获取区域代理经销商详情
 * @param {string|number} id 经销商ID
 * @returns {Promise}
 */
export function getAgentDistributorDetail(id) {
  return request({
    url: `/agent/distributors/${id}`,
    method: 'get',
  });
}

/**
 * 更新经销商信息
 * @param {string|number} id 经销商ID
 * @param {Object} data 经销商数据
 * @returns {Promise}
 */
export function updateDistributor(id, data) {
  return request({
    url: `/agent/distributors/${id}`,
    method: 'put',
    data,
  });
}

/**
 * 设置经销商状态
 * @param {string|number} id 经销商ID
 * @param {string} status 状态 (active/inactive)
 * @returns {Promise}
 */
export function setDistributorStatus(id, status) {
  return request({
    url: `/agent/distributors/${id}/status`,
    method: 'put',
    data: { status },
  });
}

/**
 * 设置经销商佣金比例
 * @param {string|number} id 经销商ID
 * @param {number} commissionRate 佣金比例
 * @returns {Promise}
 */
export function setDistributorCommissionRate(id, commissionRate) {
  return request({
    url: `/agent/distributors/${id}/commission-rate`,
    method: 'put',
    data: { commissionRate },
  });
}

/**
 * 获取区域代理订单列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getAgentOrders(params) {
  return request({
    url: '/agent/orders',
    method: 'get',
    params,
  });
}

/**
 * 获取订单详情
 * @param {string|number} id 订单ID
 * @returns {Promise}
 */
export function getAgentOrderDetail(id) {
  return request({
    url: `/agent/orders/${id}`,
    method: 'get',
  });
}

/**
 * 获取区域代理提现列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getAgentWithdrawals(params) {
  return request({
    url: '/agent/withdrawals',
    method: 'get',
    params,
  });
}

/**
 * 获取提现详情
 * @param {string|number} id 提现ID
 * @returns {Promise}
 */
export function getAgentWithdrawalDetail(id) {
  return request({
    url: `/agent/withdrawals/${id}`,
    method: 'get',
  });
}

/**
 * 申请提现
 * @param {Object} data 提现数据
 * @returns {Promise}
 */
export function createWithdrawal(data) {
  return request({
    url: '/agent/withdrawals',
    method: 'post',
    data,
  });
}

/**
 * 审核经销商提现
 * @param {string|number} id 提现ID
 * @param {Object} data 审核数据
 * @returns {Promise}
 */
export function reviewDistributorWithdrawal(id, data) {
  return request({
    url: `/agent/distributor-withdrawals/${id}/review`,
    method: 'put',
    data,
  });
}

/**
 * 获取区域代理统计数据
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getAgentStatistics(params) {
  return request({
    url: '/agent/statistics',
    method: 'get',
    params,
  });
}

/**
 * 获取区域代理个人信息
 * @returns {Promise}
 */
export function getAgentProfile() {
  return request({
    url: '/agent/profile',
    method: 'get',
  });
}

/**
 * 更新区域代理个人信息
 * @param {Object} data 个人信息数据
 * @returns {Promise}
 */
export function updateAgentProfile(data) {
  return request({
    url: '/agent/profile',
    method: 'put',
    data,
  });
}

/**
 * 更新区域代理密码
 * @param {Object} data 密码数据
 * @returns {Promise}
 */
export function updateAgentPassword(data) {
  return request({
    url: '/agent/change-password',
    method: 'put',
    data,
  });
}

/**
 * 更新USDT地址
 * @param {Object} data USDT地址数据
 * @returns {Promise}
 */
export function updateUsdtAddress(data) {
  return request({
    url: '/agent/usdt-address',
    method: 'put',
    data,
  });
}
